package com.ev.mes.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.ev.mes.dao.ProcessAutoCollectDao;
import com.ev.mes.domain.ProcessAutoCollectDO;
import com.ev.mes.service.ProcessAutoCollectService;
import com.ev.mes.vo.ProcessAutoCollectPageParam;
import com.ev.framework.utils.R;
import com.ev.apis.model.DsResultResponse;
import com.google.common.collect.Maps;


@Service
public class ProcessAutoCollectServiceImpl implements ProcessAutoCollectService {
    @Autowired
    private ProcessAutoCollectDao processAutoCollectDao;

    @Override
    public ProcessAutoCollectDO get(Long id) {
        return processAutoCollectDao.get(id);
    }

    @Override
    public List<Map<String, Object>> getDetailByProcessId(Map<String, Object> param) {
        return processAutoCollectDao.getDetailByProcessId(param);
    }

    @Override
    public List<ProcessAutoCollectDO> list(Map<String, Object> map) {
        return processAutoCollectDao.list(map);
    }

    @Override
    public int count(Map<String, Object> map) {
        return processAutoCollectDao.count(map);
    }

    @Override
    public int save(ProcessAutoCollectDO processAutoCollect) {
        return processAutoCollectDao.save(processAutoCollect);
    }

    @Override
    public int update(ProcessAutoCollectDO processAutoCollect) {
        return processAutoCollectDao.update(processAutoCollect);
    }

    @Override
    public int updateAll(ProcessAutoCollectDO processAutoCollect) {
        return processAutoCollectDao.updateAll(processAutoCollect);
    }

    @Override
    public int remove(Long id) {
        return processAutoCollectDao.remove(id);
    }

    @Override
    public int batchRemove(Long[] ids) {
        return processAutoCollectDao.batchRemove(ids);
    }

    @Override
    public R saveAndVerify(ProcessAutoCollectDO saveParam) {
        if (saveParam.getId() != null) {
            return processAutoCollectDao.update(saveParam) > 0 ? R.ok() : R.error();
        }
        return processAutoCollectDao.save(saveParam) > 0 ? R.ok() : R.error();
    }

    @Override
    public Map<String, Object> getById(Long id) {
        ProcessAutoCollectDO processAutoCollect = processAutoCollectDao.get(id);
        Map<String, Object> result = Maps.newHashMap();
        if (processAutoCollect !=null){
            result.put("data",processAutoCollect);
            return result;
        }
        return result;
    }

    @Override
    public Map<String, Object> pageList(ProcessAutoCollectPageParam pageParam) {
        Map<String, Object> result = Maps.newHashMap();
        List<Map<String, Object>> data = processAutoCollectDao.pageList(pageParam);
        if (data.size() > 0) {
            int total = processAutoCollectDao.pageCount(pageParam);
            result.put("data", new DsResultResponse(pageParam.getPageno(), pageParam.getPagesize(), total, data));
        }
        return result;
    }

}
